package br.ufrj.dcc.smarthotel.controls;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;

public class Control {
	protected final String baseURI = "http://192.168.0.140/smart-hotel-services/";
	
	protected boolean doDelete (String entity) {
		boolean responseLocation = false;
		
		ControlNetworkUtil networkUtil = ControlNetworkUtil.getInstance();
		
		try {
			responseLocation = networkUtil.doDelete(this.baseURI + entity);
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return responseLocation;
	}
	
	protected String doPost (String entity, Map<String, Object> parameters) {
		String responseLocation = null;
		
		ControlNetworkUtil networkUtil = ControlNetworkUtil.getInstance();
		
		try {
			responseLocation = networkUtil.doPost(this.baseURI + entity, parameters);
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return responseLocation;
	}
	
	protected Object retrieve(String url, Type objectType) {
		ControlNetworkUtil networkUtil = ControlNetworkUtil.getInstance();
		
		return networkUtil.retrieve(url, objectType);
	}
}
